package com.ruoyi.web.controller.businessSettings;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ScanOrderSettings;
import com.ruoyi.system.service.IScanOrderSettingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 扫码开单设置 Controller
 *
 * @author ruoyi
 * @date 2025-05-15
 */
@Api(tags="扫码开单设置")
@RestController
@RequestMapping("/system/scanOrderSettings")
public class ScanOrderSettingsController extends BaseController
{
    @Autowired
    private IScanOrderSettingsService scanOrderSettingsService;

    /**
     * 查询扫码开单设置列表
     */
    @ApiOperation("查询扫码开单设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScanOrderSettings scanOrderSettings)
    {
        startPage();
        List<ScanOrderSettings> list = scanOrderSettingsService.selectScanOrderSettingsList(scanOrderSettings);
        return getDataTable(list);
    }

    /**
     * 导出扫码开单设置列表
     */
    @ApiOperation("导出扫码开单设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:export')")
    @Log(title = "扫码开单设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScanOrderSettings scanOrderSettings)
    {
        List<ScanOrderSettings> list = scanOrderSettingsService.selectScanOrderSettingsList(scanOrderSettings);
        ExcelUtil<ScanOrderSettings> util = new ExcelUtil<ScanOrderSettings>(ScanOrderSettings.class);
        util.exportExcel(response, list, "扫码开单设置数据");
    }

    /**
     * 通过id获取扫码开单设置详细信息
     */
    @ApiOperation("通过id获取扫码开单设置详细信息")
    @PreAuthorize("@ss.hasPermi('system:settings:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scanOrderSettingsService.selectScanOrderSettingsById(id));
    }

    /**
     * 新增扫码开单设置列表
     */
    @ApiOperation("新增扫码开单设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:add')")
    @Log(title = "扫码开单设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScanOrderSettings scanOrderSettings)
    {
        return toAjax(scanOrderSettingsService.insertScanOrderSettings(scanOrderSettings));
    }

    /**
     * 修改扫码开单设置列表
     */
    @ApiOperation("修改扫码开单设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:edit')")
    @Log(title = "扫码开单设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScanOrderSettings scanOrderSettings)
    {
        return toAjax(scanOrderSettingsService.updateScanOrderSettings(scanOrderSettings));
    }

    /**
     * 通过id批量删除扫码开单设置信息
     */
    @ApiOperation("通过id批量删除扫码开单设置信息")
    @PreAuthorize("@ss.hasPermi('system:settings:remove')")
    @Log(title = "扫码开单设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scanOrderSettingsService.deleteScanOrderSettingsByIds(ids));
    }

    /**
     * 根据门店ID查询扫码开单设置详情
     */
    @ApiOperation("根据门店ID查询扫码开单设置详情")
    @PreAuthorize("@ss.hasPermi('system:settings:query')")
    @GetMapping("/detail/{storeId}")
    public AjaxResult getTableSettingsDetail(@PathVariable("storeId") Long storeId) {
        ScanOrderSettings scanOrderSettings = scanOrderSettingsService.selectByStoreId(storeId);
        return success(scanOrderSettings);
    }

}
